package com.nest.WorkNest.act;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lidroid.xutils.exception.HttpException;
import com.nest.WorkNest.R;
import com.nest.WorkNest.api.XutilsPost;
import com.nest.WorkNest.entity.AddShoppingCart;
import com.nest.WorkNest.entity.ProductDetailCart;
import com.nest.WorkNest.tools.ParseUtils;
import com.nest.WorkNest.tools.Tool;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.orhanobut.logger.Logger;
import com.stevenhu.android.phone.bean.ADInfo;
import com.stevenhu.android.phone.utils.ViewFactory;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.androiddevelop.cycleviewpager.lib.CycleViewPager;

public class ProductDetailAct extends BaseActivity implements OnClickListener {

    @Bind(R.id.product_productname)
    TextView productProductname;
    @Bind(R.id.product_productId)
    TextView productProductId;
    @Bind(R.id.product_minOrderNumber)
    TextView productMinOrderNumber;
    @Bind(R.id.product_quotation)
    TextView productQuotation;
    @Bind(R.id.product_optOrderNumber)
    TextView productOptOrderNumber;
    @Bind(R.id.product_quotation2)
    TextView productQuotation2;
    @Bind(R.id.product_bookedQuantity)
    TextView productBookedQuantity;
    @Bind(R.id.product_splId)
    TextView productSplId;
    @Bind(R.id.product_select)
    LinearLayout productSelect;
    @Bind(R.id.product_productType)
    TextView productProductType;
    @Bind(R.id.product_productStyle)
    TextView productProductStyle;
    @Bind(R.id.product_productDescription)
    TextView productProductDescription;
    @Bind(R.id.product_fabricContent)
    TextView productFabricContent;
    @Bind(R.id.product_color)
    TextView productColor;
    @Bind(R.id.product_size)
    TextView productSize;
    @Bind(R.id.product_predictProTime)
    TextView productPredictProTime;
    @Bind(R.id.product_orderModelTime)
    TextView productOrderModelTime;
    @Bind(R.id.product_designerId)
    TextView productDesignerId;
    @Bind(R.id.product_requiredExplain)
    LinearLayout productRequiredExplain;
    @Bind(R.id.product_deliveryTime)
    LinearLayout productDeliveryTime;
    @Bind(R.id.product_deliveryWay)
    LinearLayout productDeliveryWay;
    @Bind(R.id.product_selectAddress)
    LinearLayout productSelectAddress;
    @Bind(R.id.btn_productdetail_addshoppingcart)
    Button btnProductdetailAddshoppingcart;
    @Bind(R.id.btn_productdetail_pay)
    Button btnProductdetailPay;
    @Bind(R.id.tv_product_totalnumber)
    TextView tvProductTotalnumber;
    @Bind(R.id.tv_product_requiredExplain)
    TextView tvProductRequiredExplain;
    @Bind(R.id.tv_product_deliveryTime)
    TextView tvProductDeliveryTime;
    @Bind(R.id.tv_product_selectAddress)
    TextView tvProductSelectAddress;
    @Bind(R.id.tv_product_deliveryWay)
    TextView tvProductDeliveryWay;
    @Bind(R.id.btn_productdetail_yes)
    Button btnProductdetailYes;
    @Bind(R.id.ll_productdetail_bottom)
    LinearLayout llProductdetailBottom;
    @Bind(R.id.btn_productdetail_recommend)
    Button btn_productdetail_recommend;
    @Bind(R.id.tv_product_percentage)
    TextView tvProductPercentage;
    @Bind(R.id.ll_product_percentage)
    LinearLayout llProductPercentage;
    private List<ImageView> views = new ArrayList<ImageView>();
    private List<ADInfo> infos = new ArrayList<ADInfo>();
    private CycleViewPager cycleViewPager;
    //    private ImageView imageView;
//    private AtomicInteger atomicInteger = new AtomicInteger(0);
//    private boolean isContinue = true;
    private Context context = ProductDetailAct.this;
    private boolean isfavorite = false;
    private ArrayList<HashMap<String, String>> addressinfo = new ArrayList<>();
    private ArrayList<HashMap<String, String>> shoppingcartdata = new ArrayList<>();
    private String productId, favoritetype, cartType, colors, sizes, requiredExplain,
            deliveryTime, deliveryWay, productName, addressId, productType, productStatus, applyType, shoppingcartId, productimgUrl;
    private HashMap<String, String> data = new HashMap<>();
    private String[] color, size, imgUrl;
    private ArrayList<HashMap<String, String>> getdataList = new ArrayList<>();
    private ArrayList<HashMap<String, String>> imgList = new ArrayList<HashMap<String, String>>();
    private Intent mIntent = new Intent();
    private ProductDetailCart productDetailCart;
    private AddShoppingCart addShoppingCart;
    private Intent intent = new Intent();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_productdetail);
        ButterKnife.bind(this);
        initProgress(context, "提交中...");
        if (!TextUtils.isEmpty(getIntent().getStringExtra("productId"))) {
            productId = getIntent().getStringExtra("productId");
            productimgUrl = getIntent().getStringExtra("mainImage");
        }
        if (!TextUtils.isEmpty(getIntent().getStringExtra("status"))) {
            productStatus = getIntent().getStringExtra("status");
        }
        loadProductDetail();
        initView();
        configImageLoader();

    }

    private void initView() {
        initBar();
        productDetailCart = new ProductDetailCart();
        actionbar_side_name.setVisibility(View.VISIBLE);
        actionbar_side_name.setText("产品详情");
        ll_iv_actionbar_side_left.setVisibility(View.VISIBLE);
        ll_tv_actionbar_side_right.setVisibility(View.VISIBLE);
        tv_actionbar_side_right.setBackgroundResource(R.drawable.btn_productdetail_favorite);
        ll_iv_actionbar_side_right.setVisibility(View.GONE);
        back();
        if (!getStringExtra("my").equals("1")) {
            btn_productdetail_recommend.setVisibility(View.INVISIBLE);
        } else {
            llProductPercentage.setVisibility(View.VISIBLE);
        }
        if (getIntent().getIntExtra("shoppingcart", 0) == 1) {
            llProductdetailBottom.setVisibility(View.GONE);
            btnProductdetailYes.setVisibility(View.VISIBLE);
            shoppingcartId = getIntent().getStringExtra("id");
            loadqueryShoppingCartRecords(shoppingcartId);
        } else {
            if (productStatus.equals("0")) {
                btn_productdetail_recommend.setVisibility(View.GONE);
            } else if (productStatus.equals("2") || productStatus.equals("1")) {
//            applyType = "1";
                btn_productdetail_recommend.setText("申请上架");
            } else if (productStatus.equals("4")) {
//            applyType = "0";
                btn_productdetail_recommend.setText("申请下架");
            } else if (productStatus.equals("8")) {
                btn_productdetail_recommend.setText("审核中");
            }
        }
        btn_productdetail_recommend.setOnClickListener(this);
        ll_tv_actionbar_side_right.setOnClickListener(this);
        productSelect.setOnClickListener(this);
        productSelect.setOnClickListener(this);
        productRequiredExplain.setOnClickListener(this);
        productDeliveryTime.setOnClickListener(this);
        productDeliveryWay.setOnClickListener(this);
        productSelectAddress.setOnClickListener(this);
        btnProductdetailPay.setOnClickListener(this);
        btnProductdetailAddshoppingcart.setOnClickListener(this);
        btnProductdetailYes.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        mIntent.setClass(context, CreateAct.class);
        switch (v.getId()) {
            case R.id.btn_productdetail_recommend:
                if (productStatus.equals("4")) {
                    loadApply("0");
                } else if (productStatus.equals("2") || productStatus.equals("1")) {
                    Intent intent = new Intent(context, RecommendAct.class);
                    intent.putExtra("productId", productId);
                    startActivity(intent);
                }
                break;
            case R.id.ll_tv_actionbar_side_right:
                if (isfavorite) {
                    favoritetype = "0";
                    isfavorite = true;
                } else {
                    favoritetype = "1";
                    isfavorite = false;
                }
                loadFavorite();
                break;
            case R.id.product_select:
                intent.setClass(context, ProductSelectAct.class);
                Bundle bundle = new Bundle();
                bundle.putStringArray("color", color);
                bundle.putStringArray("size", size);
                bundle.putInt("minOrderNumber", productDetailCart.getMinOrderNumber());
                intent.putExtras(bundle);
                startActivityForResult(intent, 1);
                break;
            case R.id.product_requiredExplain:
                mIntent.putExtra("type", "RE");
                startActivityForResult(mIntent, 2);
                break;
            case R.id.product_deliveryTime:
                mIntent.putExtra("type", "DT");
                startActivityForResult(mIntent, 3);
                break;
            case R.id.product_deliveryWay:
                mIntent.putExtra("type", "DW");
                startActivityForResult(mIntent, 4);
                break;
            case R.id.product_selectAddress:
                Intent sIntent = new Intent(context, AddressSelectAct.class);
                startActivityForResult(sIntent, 5);
                break;

            case R.id.btn_productdetail_pay:
                if (!(getdataList == null || TextUtils.isEmpty(requiredExplain) || TextUtils.isEmpty(deliveryTime)
                        || TextUtils.isEmpty(deliveryWay) || TextUtils.isEmpty(addressId))) {
                    Intent ointent = new Intent(context, OrderChangeAct.class);
                    ointent.putExtra("productDetailCart", productDetailCart);
                    ointent.putExtra("addressId", addressId);
                    ointent.putExtra("productId", productId);
                    ointent.putExtra("productName", productName);
                    ointent.putExtra("requiredExplain", requiredExplain);
                    ointent.putExtra("deliveryTime", deliveryTime);
                    ointent.putExtra("deliveryWay", deliveryWay);
                    ointent.putExtra("productType", productType);
                    ointent.putExtra("productimgUrl", productimgUrl);
                    startActivity(ointent);
                    finish();
                } else {
                    showToast("请选择所有信息");
                }
                break;
            case R.id.btn_productdetail_addshoppingcart:
                if (!(getdataList == null || TextUtils.isEmpty(requiredExplain) || TextUtils.isEmpty(deliveryTime)
                        || TextUtils.isEmpty(deliveryWay) || TextUtils.isEmpty(addressId))) {
                    initData("1");
                } else {
                    showToast("请选择所有信息");
                }
                break;
            case R.id.btn_productdetail_yes:
                if (!(getdataList == null || TextUtils.isEmpty(requiredExplain) || TextUtils.isEmpty(deliveryTime)
                        || TextUtils.isEmpty(deliveryWay) || TextUtils.isEmpty(addressId))) {
                    initData("2");
                } else {
                    showToast("请选择所有信息");
                }
                break;
        }

    }

    public void loadFavorite() {
        XutilsPost xutilsPost = new XutilsPost();
        XutilsPost.IOAuthCallBack ioAuthCallBack = new XutilsPost.IOAuthCallBack() {
            @Override
            public void getIOAuthCallBack(String result) {
//                Logger.json(result);
                if (Tool.getString(result, "resultCode").equals("0")) {
                    showToast(Tool.getString(result, "MSG"));
                    if (isfavorite) {
                        isfavorite = false;
                    } else {
                        isfavorite = true;
                    }
                } else if (Tool.getString(result, "resultCode").equals("9001")) {
                    showToast("token已过期，请重新登录");
                    Intent intent = new Intent(context, LoginAct.class);
                    startActivity(intent);
                    finish();
                }
            }

            @Override
            public void getDealException(HttpException httpException, String result) {

            }

            @Override
            public void getLoadingCallBack(long total, long current, boolean isUploading) {

            }
        };
        xutilsPost.doPostFavorite(context, productId, favoritetype, ioAuthCallBack);
    }

    public void loadAddShoppingCart(final String Type, ArrayList<HashMap<String, String>> dataList) {
        XutilsPost xutilsPost = new XutilsPost();
        XutilsPost.IOAuthCallBack ioAuthCallBack = new XutilsPost.IOAuthCallBack() {
            @Override
            public void getIOAuthCallBack(String result) {
                if (Tool.getString(result, "resultCode").equals("0")) {
                    if (Type.equals("2")) {
                        showToast("修改购物车成功");
                        finish();
                    } else {
                        showToast("加入购物车成功");
                    }

                } else if (Tool.getString(result, "resultCode").equals("9001")) {
                    showToast("token已过期，请重新登录");
                    Intent intent = new Intent(context, LoginAct.class);
                    startActivity(intent);
                    finish();
                }
            }

            @Override
            public void getDealException(HttpException httpException, String result) {

            }

            @Override
            public void getLoadingCallBack(long total, long current, boolean isUploading) {

            }
        };
        xutilsPost.doPostAddShoppingCart(context, addShoppingCart, Type, dataList, ioAuthCallBack);

    }

    public void loadProductDetail() {
        XutilsPost xutilsPost = new XutilsPost();
        XutilsPost.IOAuthCallBack ioAuthCallBack = new XutilsPost.IOAuthCallBack() {
            @Override
            public void getIOAuthCallBack(String result) {
                if (Tool.getString(result, "resultCode").equals("0")) {
                    Logger.json(result);
                    data = Tool.getMapByJsonObj(result);
                    productProductname.setText(data.get("productName"));
                    productProductId.setText(data.get("productId"));
                    productProductType.setText(data.get("productType"));
                    productProductStyle.setText(data.get("productStyle"));
                    productProductDescription.setText(data.get("productDescription"));
                    productFabricContent.setText(data.get("fabricContent"));
                    productColor.setText(data.get("color"));
                    productSize.setText(data.get("size"));
                    productOrderModelTime.setText(((data.get("orderModelTime")).split("T"))[0]);
                    productSplId.setText(data.get("splId"));
                    productPredictProTime.setText((data.get("predictProTime").split("T"))[0]);
                    productDesignerId.setText(data.get("designerId"));
                    productMinOrderNumber.setText(data.get("minOrderNumber") + "件 起批");
                    productQuotation.setText("￥" + data.get("quotation"));
                    productOptOrderNumber.setText("≥" + data.get("optOrderNumber") + "件");
                    productQuotation2.setText("￥" + data.get("quotation2"));
                    productBookedQuantity.setText(data.get("bookedQuantity") + "件");
                    if (!TextUtils.isEmpty(data.get("percentage"))) {
                        if (ParseUtils.string2float(data.get("percentage")) == 0f)
                            llProductPercentage.setVisibility(View.GONE);
                        else
                            tvProductPercentage.setText(data.get("percentage"));
                    }
                    colors = Tool.getString(result, "color");
                    sizes = Tool.getString(result, "size");
                    color = colors.split(";");
                    size = sizes.split(";");
                    productName = data.get("productName");
                    productType = data.get("productType");
                    productDetailCart.setMinOrderNumber(ParseUtils.string2int(data.get("minOrderNumber")));
                    productDetailCart.setOptOrderNumber(ParseUtils.string2int(data.get("optOrderNumber")));
                    productDetailCart.setMinquotation(ParseUtils.string2float(data.get("quotation")));
                    productDetailCart.setOptquotation(ParseUtils.string2float(data.get("quotation2")));
                    JSONArray imgarray = Tool.getJsonArray(result, "datalist");
                    imgList.clear();
                    imgList = Tool.getListMapByJsonArray(imgarray);
                    imgUrl = new String[imgList.size()];
                    for (int i = 0; i < imgList.size(); i++) {
                        String image = imgList.get(i).get("url");
                        if (!image.substring(0, 1).equals("h")) {
                            image = "http://" + image;
                        }
                        imgUrl[i] = image;
                    }
                    if (imgList.size() != 0) {
                        initialize();
                    }
                } else if (Tool.getString(result, "resultCode").equals("9001")) {
                    showToast("token已过期，请重新登录");
                    Intent intent = new Intent(context, LoginAct.class);
                    startActivity(intent);
                    finish();
                }
            }

            @Override
            public void getDealException(HttpException httpException, String result) {

            }

            @Override
            public void getLoadingCallBack(long total, long current, boolean isUploading) {
//                Logger.d(current + "/" + total);
//                Logger.d(isUploading + "");
            }
        };
        xutilsPost.doPostProductDetail(context, productId, ioAuthCallBack);
    }

    public void initData(String cartType) {
        int all = 0;
        float totalprice;
        addShoppingCart = new AddShoppingCart();
        for (int i = 0; i < getdataList.size(); i++) {
            all += ParseUtils.string2int(getdataList.get(i).get("number"));
        }
        if (all >= productDetailCart.getMinOrderNumber() && all < productDetailCart.getOptOrderNumber()) {
            totalprice = productDetailCart.getMinquotation() * all;
            addShoppingCart.setPerPrice(productDetailCart.getMinquotation());
            addShoppingCart.setTotalPrice(totalprice);
        } else if (all >= productDetailCart.getOptOrderNumber()) {
            totalprice = productDetailCart.getOptquotation() * all;
            addShoppingCart.setPerPrice(productDetailCart.getOptquotation());
            addShoppingCart.setTotalPrice(totalprice);
        }
        addShoppingCart.setRequiredExplain(requiredExplain);
        addShoppingCart.setDeliveryWay(deliveryWay);
        addShoppingCart.setDeliveryTime(deliveryTime);
        addShoppingCart.setAddressId(addressId);
        addShoppingCart.setProductId(productId);
        addShoppingCart.setProductName(productName);
        addShoppingCart.setTotalQuantity(all);
        if (addShoppingCart != null) {
            loadAddShoppingCart(cartType, getdataList);
        } else {
            showToast("请选择所有信息");
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {

            switch (requestCode) {
                case 1:
                    getdataList = (ArrayList<HashMap<String, String>>) data.getSerializableExtra("getdatalist");
                    productDetailCart.setGetdatalist(getdataList);
                    intent.putExtra("getdatalist", getdataList);
                    tvProductTotalnumber.setText("" + data.getIntExtra("all", 0) + " 件");
                    break;

                case 2:
                    requiredExplain = data.getStringExtra("RE");
                    mIntent.putExtra("RE", requiredExplain);
                    productDetailCart.setRequiredExplain(requiredExplain);
                    tvProductRequiredExplain.setText(requiredExplain);
                    break;

                case 3:
                    deliveryTime = data.getStringExtra("time");
                    mIntent.putExtra("DT", deliveryTime);
                    productDetailCart.setDeliveryTime(deliveryTime);
                    tvProductDeliveryTime.setText(deliveryTime);
                    break;

                case 4:
                    deliveryWay = data.getStringExtra("DW");
                    mIntent.putExtra("DW", deliveryWay);
                    productDetailCart.setDeliveryWay(deliveryWay);
                    tvProductDeliveryWay.setText(deliveryWay);
                    break;

                case 5:
                    addressId = data.getStringExtra("addressId");
                    loadAddressInfo(addressId);
                    mIntent.putExtra("addressId", addressId);
                    break;
            }
        }
    }

    public void loadApply(String applyType) {
        XutilsPost xutilsPost = new XutilsPost();
        XutilsPost.IOAuthCallBack ioAuthCallBack = new XutilsPost.IOAuthCallBack() {
            @Override
            public void getIOAuthCallBack(String result) {
                if (Tool.getString(result, "resultCode").equals("0")) {
                    showToast("操作成功");
                    btn_productdetail_recommend.setText("审核中");
                } else if (Tool.getString(result, "resultCode").equals("9001")) {
                    showToast("token已过期，请重新登录");
                    Intent intent = new Intent(context, LoginAct.class);
                    startActivity(intent);
                    finish();
                }
                if (pd.isShowing())
                    pd.cancel();
            }

            @Override
            public void getDealException(HttpException httpException, String result) {
                if (pd.isShowing())
                    pd.cancel();
            }

            @Override
            public void getLoadingCallBack(long total, long current, boolean isUploading) {
                if (isUploading) {
                    pd.show();
                }
            }
        };
        xutilsPost.doPostUnApply(context, applyType, productId, ioAuthCallBack);
    }

    @SuppressLint("NewApi")
    private void initialize() {

        cycleViewPager = (CycleViewPager) getFragmentManager()
                .findFragmentById(com.stevenhu.android.phone.ui.R.id.fragment_cycle_viewpager_content);
        for (int i = 0; i < imgUrl.length; i++) {
            ADInfo info = new ADInfo();
            info.setUrl(imgUrl[i]);
            info.setContent("图片-->" + i);
            infos.add(info);
        }
        // 将最后一个ImageView添加进来
        views.add(ViewFactory.getImageView(this, infos.get(infos.size() - 1).getUrl()));
        for (int i = 0; i < infos.size(); i++) {
            views.add(ViewFactory.getImageView(this, infos.get(i).getUrl()));
        }
        // 将第一个ImageView添加进来
        views.add(ViewFactory.getImageView(this, infos.get(0).getUrl()));

        for (int j = 0; j < views.size(); j++) {
            views.get(j).setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        }
        // 设置循环，在调用setData方法前调用
        cycleViewPager.setCycle(true);

        // 在加载数据前设置是否循环
        cycleViewPager.setData(views, infos, mAdCycleViewListener);
        //设置轮播
        cycleViewPager.setWheel(true);

        // 设置轮播时间，默认5000ms
        cycleViewPager.setTime(5000);
        //设置圆点指示图标组居中显示，默认靠右
        cycleViewPager.setIndicatorCenter();
    }

    private CycleViewPager.ImageCycleViewListener mAdCycleViewListener = new CycleViewPager.ImageCycleViewListener() {

        @Override
        public void onImageClick(ADInfo info, int position, View imageView) {
            if (cycleViewPager.isCycle()) {
                position = position - 1;
            }

        }

    };

    /**
     * 配置ImageLoder
     */
    private void configImageLoader() {
        // 初始化ImageLoader
        @SuppressWarnings("deprecation")
        DisplayImageOptions options = new DisplayImageOptions.Builder().showStubImage(com.stevenhu.android.phone.ui.R.drawable.icon_stub) // 设置图片下载期间显示的图片
                .showImageForEmptyUri(com.stevenhu.android.phone.ui.R.drawable.icon_empty) // 设置图片Uri为空或是错误的时候显示的图片
                .showImageOnFail(com.stevenhu.android.phone.ui.R.drawable.icon_error) // 设置图片加载或解码过程中发生错误显示的图片
                .cacheInMemory(true) // 设置下载的图片是否缓存在内存中
                .cacheOnDisc(true) // 设置下载的图片是否缓存在SD卡中
                        // .displayer(new RoundedBitmapDisplayer(20)) // 设置成圆角图片
                .build(); // 创建配置过得DisplayImageOption对象

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).defaultDisplayImageOptions(options)
                .threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory()
                .discCacheFileNameGenerator(new Md5FileNameGenerator()).tasksProcessingOrder(QueueProcessingType.LIFO).build();
        ImageLoader.getInstance().init(config);
    }


    private void loadAddressInfo(String addressId) {
        XutilsPost xutilsPost = new XutilsPost();
        XutilsPost.IOAuthCallBack ioAuthCallBack = new XutilsPost.IOAuthCallBack() {
            @Override
            public void getIOAuthCallBack(String result) {
                JSONObject jsonObject = Tool.getJsonObject(result);
                JSONArray jsonArray;
                if (Tool.getString(jsonObject, "resultCode").equals("0")) {
                    jsonArray = Tool.getJsonArray(result, "dataList");
                    addressinfo = Tool.getListMapByJsonArray(jsonArray);
                    tvProductSelectAddress.setText(addressinfo.get(0).get("province") + "省"
                            + addressinfo.get(0).get("city") + addressinfo.get(0).get("address"));
                } else if (Tool.getString(result, "resultCode").equals("9001")) {
                    showToast("token已过期，请重新登录");
                    Intent intent = new Intent(context, LoginAct.class);
                    startActivity(intent);
                    finish();
                }
            }

            @Override
            public void getDealException(HttpException httpException, String result) {

            }

            @Override
            public void getLoadingCallBack(long total, long current, boolean isUploading) {

            }
        };
        xutilsPost.doPostAddressList(context, addressId, ioAuthCallBack);
    }

    public void loadqueryShoppingCartRecords(String id) {
        XutilsPost xutilsPost = new XutilsPost();
        XutilsPost.IOAuthCallBack ioAuthCallBack = new XutilsPost.IOAuthCallBack() {
            @Override
            public void getIOAuthCallBack(String result) {

                if (Tool.getString(result, "resultCode").equals("0")) {
                    Logger.json(result);

                } else if (Tool.getString(result, "resultCode").equals("9001")) {
                    showToast("token已过期，请重新登录");
                    Intent intent = new Intent(context, LoginAct.class);
                    startActivity(intent);
                    finish();
                }
            }

            @Override
            public void getDealException(HttpException httpException, String result) {

            }

            @Override
            public void getLoadingCallBack(long total, long current, boolean isUploading) {


            }
        };
        xutilsPost.doPostqueryShoppingCartRecords(context, id, ioAuthCallBack);
    }

}